package com.xxx.video.dynamic.presenters;

import android.content.Context;
import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.xxx.video.commen.beans.BaseBean;
import com.xxx.video.commen.presenters.BasePresenter;
import com.xxx.video.commen.utils.ResponseUtils;
import com.xxx.video.dynamic.beans.ChatListBean;
import com.xxx.video.network.listeners.CommonResponseListener;
import com.xxx.video.network.utils.NetWorkUtils;

public class ChatPresenter extends BasePresenter<IChatView> {

    public ChatPresenter(@NonNull Context context, IChatView baseView) {
        super(context, baseView);
    }

    /**
     * get  interactionList
     *
     * @param userId user id
     * @param page   page
     */
    public void interactionList(String userId, int page) {
        NetWorkUtils.getInstance().interactionList(userId, String.valueOf(page), new CommonResponseListener<ChatListBean>() {

            @Override
            public void onSuccess(ChatListBean successOb, String result) {
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().initData2View(successOb.page.list);
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {

            }
        });
    }

    /**
     * add  Interaction
     *
     * @param userId   user id
     * @param userName user name
     */
    public void addInteraction(String userId, String userName) {
        String content = getBaseView() == null ? "" : getBaseView().getContent();
        if (TextUtils.isEmpty(content)) {
            return;
        }
        NetWorkUtils.getInstance().addInteraction(userId, userName, content, new CommonResponseListener<BaseBean>() {

            @Override
            public void onSuccess(BaseBean successOb, String result) {
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().addContentSuccess(content);
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {

            }
        });

    }
}
